# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=asn1crypto
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.24.0
pkgrel=1
pkgdesc="Python ASN.1 library with a focus on performance and a pythonic API (mingw-w64)"
url='https://github.com/wbond/asn1crypto'
license=('MIT')
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/wbond/asn1crypto/archive/${pkgver}.tar.gz")
sha256sums=('d2a82bb3c29e1abcb376b59679510b58dd796c813f8983f2db9b45e9ab228190')

prepare() {
  cd ${srcdir}
  cp -r ${_realname}-${pkgver} python2-build-${CARCH}
  cp -r ${_realname}-${pkgver} python3-build-${CARCH}
}

build() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-asn1crypto() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-pycparser")
  cd ${srcdir}/python3-build-${CARCH}
  ${MINGW_PREFIX}/bin/python3 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-${_realname}/LICENSE
}

package_python2-asn1crypto() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-pycparser")
  cd ${srcdir}/python2-build-${CARCH}
  ${MINGW_PREFIX}/bin/python2 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-asn1crypto() {
  package_python2-asn1crypto
}

package_mingw-w64-i686-python3-asn1crypto() {
  package_python3-asn1crypto
}

package_mingw-w64-x86_64-python2-asn1crypto() {
  package_python2-asn1crypto
}

package_mingw-w64-x86_64-python3-asn1crypto() {
  package_python3-asn1crypto
}
